<template>
	<Row>
		<Col span='6'>
		<Tree :data="data1" @on-select-change='onSelect'></Tree>
		<br>
		<Button type="success" @click='sesee'>查看图片</Button>
		</Col>
		
		<Col span="18">
		<Upload multiple type="drag" name='avatar' :action="imgUrl">
			<div style="padding: 20px 0">
				<Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
				<p>点击或将文件拖拽到这里上传</p>
			</div>
		</Upload>
		

		<div class="demo-upload-list" v-for="item in paths" style="width: 150px;float: left;">
			<img :src="item" style="width: 100%;">
		</div>
		</Col>
	</Row>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				paths: [],
				data1: [],
				cateId:'',
				imgUrl:'http://localhost:3000/upload/upload'
			}
		},
		methods: {
			getData() {
				this.$http.get('http://localhost:3000/upload/list').then(res => {

					let ll = res.data.length
					let enen = ''
					for(let i = 0; i < ll; i++) {
						enen = 'http://localhost:3000/' + res.data[i].filename
						this.paths.push(enen)
					}
				})
			},
			sesee() {
				this.paths = []
				this.getData()
			},
			sTree(res, tchild) {
				let len = res.length
				for(let i = 0; i < len; i++) {
					if(res[i].children) {
						let obj = {
							title: res[i].text,
							expand: true,
							id: res[i]._id,
							children: []
						}
						tchild.push(obj)
						this.sTree(res[i].children, tchild[i].children)
					} else {
						let obj = {
							title: res[i].text,
							id: res[i]._id,
						}
						tchild.push(obj)
					}
				}

			},
			typeNumber() {
				this.$http.get('http://localhost:3000/news/list').then(res => {
					let ll = res.data.length
					const arr = []
					for(let i = 0; i < ll; i++) {
						arr.push(res.data[i])
					}
					for(let i = 0; i < arr.length; i++) {
						let obj = {
							title: arr[i].text,
							expand: true,
							id: arr[i]._id,
							children: [],
						}
						this.data1.push(obj)
						if(arr[i].children) {

							this.sTree(arr[i].children, this.data1[i].children)
						}

					}

				})
			},
			onSelect(rows) {
				this.cateId=rows[0].id
				this.imgUrl='http://localhost:3000/upload/upload/'+this.cateId
				console.log(this.imgUrl)
			}
		},
		created() {
			//			getData()
			this.typeNumber()
		},
	}
</script>
<style scoped>

</style>